var express = require('express');
var router = express.Router();
let {gomodel,roomModel,userModel}=require('../model/model')
/* GET home page. */
router.get('/',async(req, res)=>{
  let gols=await gomodel.find()
  res.send({
    code:200,
    gols
  })
});
//添加房间
router.post("/addroom", (req, res) => {
  roomModel.create({roomname: req.body.roomName, users: [req.body._id, req.body.el_id], messages: []})
  res.send({
    code: 200,
    msg: "房间addok"
  })
})
//获取当前用户的所有房间
router.get('/rooms', async(req, res) => {
  let {uid} = req.query
  let roomls = await roomModel.find()
  let ls = roomls.filter(item => item.users.includes(uid))
  res.send({
    code: 200,
    ls
  })
})
//获取指定房间的所有信息
router.get("/sinroom", async(req, res) => {
  let {id} = req.query
  let roomls = await roomModel.find({_id: id})
  let info = roomls[0]
  res.send({
    code: 200,
    info
  })
})
router.get("/usermsg", async(req, res) => {
  let {id} = req.query
  let ls = await userModel.find({_id: id})
  res.send({
    code: 200,
    info: ls[0]
  })
})
module.exports = router;
